package com.zpself.module.basic.读取配置;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2020/7/14 13:55
 * @Modified By
 */
public class ReadConfigFile {
    public static void main(String[] args) {
        Properties properties = loadProps("C:\\Users\\ying\\zpFile\\newLock\\LockScreenConfig.properties");
        String sleepTime = properties.getProperty("sleepTime1");
        System.out.println("获取到属性sleepTime："+sleepTime);
    }
    public static Properties loadProps(String filePathName) {
        Properties props = new Properties();
        InputStream in = null;
        try {
            //读取配置文件
            in =new BufferedInputStream(new FileInputStream(filePathName));
            props.load(in);
        } catch (Exception e) {
            System.out.println("读取jdbc.properties时出现异常：" + e);
        } finally {
            try {
                if (null != in) {
                    in.close();
                }
            } catch (IOException e) {
                System.out.println("jdbc.properties文件流关闭出现异常");
            }
        }

        //通过key值找value值
        return props;
    }
}
